set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions=1000;
set hive.exec.max.dynamic.partitions.pernode=1000;


insert overwrite table  jms_dm.dm_spec_waybill_sum_dt partition(dt)
select 
    date_format(input_time, 'yyyy-MM-dd') as input_date
    , business_type_code
    , business_type_name
    , business_type_name_en
    , agent_code
    , agent_name
    , brand_id
    , brand_name
    , count(*)            as total_cnt
    , sum(least(remind_cnt, 1))             as remind_cnt      -- 只统计多少个运单被统计过
    , count(*) - sum(least(remind_cnt, 1))  as not_remind_cnt  -- 未提醒量, 需要提醒量去重后相减
    , dt
from 
    jms_dm.dm_spec_waybill_detail_dt
where 
    dt between date_add('{{ execution_date  | cst_ds }}', -2) and '{{ execution_date  | cst_ds }}'
group by 
    business_type_code
    , business_type_name
    , business_type_name_en
    , agent_code
    , agent_name
    , brand_id
    , brand_name
    , date_format(input_time, 'yyyy-MM-dd')
    , dt
distribute by 1
;
